{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$WARN UNSAFE_TYPE OFF}
unit WindowInterface;

interface

  uses
    Interface_TLB, ComObj, ExtActns;

  type
    TWindowInterface = class(TAutoIntfObject, IWindowIntf, IDispatch)
      protected
        function Get_Width: Integer; safecall;
        procedure Set_Width(Value: Integer); safecall;
        function Get_Height: Integer; safecall;
        procedure Set_Height(Value: Integer); safecall;
        function Get_minWidth: Integer; safecall;
        procedure Set_minWidth(Value: Integer); safecall;
        function Get_minHeight: Integer; safecall;
        procedure Set_minHeight(Value: Integer); safecall;
        function Get_maxWidth: Integer; safecall;
        procedure Set_maxWidth(Value: Integer); safecall;
        function Get_maxHeight: Integer; safecall;
        procedure Set_maxHeight(Value: Integer); safecall;
        function Get_State: Integer; safecall;
        procedure Set_State(Value: Integer); safecall;
        procedure Close; safecall;
        property Width: Integer read Get_Width write Set_Width;
        property Height: Integer read Get_Height write Set_Height;
        property minWidth: Integer read Get_minWidth write Set_minWidth;
        property minHeight: Integer read Get_minHeight write Set_minHeight;
        property maxWidth: Integer read Get_maxWidth write Set_maxWidth;
        property maxHeight: Integer read Get_maxHeight write Set_maxHeight;
        property State: Integer read Get_State write Set_State;
      public
        constructor Create();
        destructor Destroy(); override;
    end;

implementation

  uses
    ActiveX, StdActns, Dialogs, SysUtils, Variants, Main, Forms;

//*********************
//* TPootcherInterface
//*********************
  constructor TWindowInterface.Create();
  var
    TypeLib : ITypeLib;
    ExeName : WideString;
  begin
    //Get name of application
    ExeName := ParamStr(0);
    //Load type library from application's resources
    OleCheck(LoadTypeLib(PWideChar(ExeName), TypeLib));
    //Inherit
    inherited Create(TypeLib, IWindowIntf);
  end;

  destructor TWindowInterface.Destroy();
  begin
    inherited;
  end;

  function TWindowInterface.Get_Width() : Integer;
  begin
    Result := MainForm.Width;
  end;

  procedure TWindowInterface.Set_Width(Value : Integer);
  begin
    try
      MainForm.Width := Value;
      MainForm.Left := MainForm.Monitor.Left + Round((MainForm.Monitor.Width / 2) - (MainForm.Width / 2));
    except end;
  end;

  function TWindowInterface.Get_Height() : Integer;
  begin
    Result := MainForm.Height;
  end;

  procedure TWindowInterface.Set_Height(Value : Integer);
  begin
    try
      MainForm.Height := Value;
      MainForm.Top := MainForm.Monitor.Top + Round((MainForm.Monitor.Height / 2) - (MainForm.Height / 2));
    except end;
  end;

  function TWindowInterface.Get_minWidth() : Integer;
  begin
    Result:= MainForm.Constraints.MinWidth;
  end;

  procedure TWindowInterface.Set_minWidth(Value : Integer);
  begin
    try
      MainForm.Constraints.MinWidth := Value;
    except end;
  end;

  function TWindowInterface.Get_minHeight() : Integer;
  begin
    Result := MainForm.Constraints.MinHeight;
  end;

  procedure TWindowInterface.Set_minHeight(Value : Integer);
  begin
    try
      MainForm.Constraints.MinHeight := Value;
    except end;
  end;

  function TWindowInterface.Get_maxWidth() : Integer;
  begin
    Result:= MainForm.Constraints.MaxWidth;
  end;

  procedure TWindowInterface.Set_maxWidth(Value : Integer);
  begin
    try
      MainForm.Constraints.MaxWidth := Value;
    except end;
  end;

  function TWindowInterface.Get_maxHeight() : Integer;
  begin
    Result := MainForm.Constraints.MaxHeight;
  end;

  procedure TWindowInterface.Set_maxHeight(Value : Integer);
  begin
    try
      MainForm.Constraints.MaxHeight := Value;
    except end;
  end;

  function TWindowInterface.Get_State() : Integer;
  begin
    Result := Integer(MainForm.WindowState);
  end;

  procedure TWindowInterface.Set_State(Value: Integer);
  begin
    if (Value >= 0) and (Value <= 2) then
      try
        MainForm.WindowState := TWindowState(Value);
      except end;
  end;

  procedure TWindowInterface.Close();
  begin
    try
      MainForm.Close();
    except end;
  end;

end.
